import request from '@/config/axios'
import 'uno.css'
//import request from '@/utils/request'

// 客户信息 VO
export interface CustInfoVO {
  id: number
  code: string
  personName: string
  personMnemonicWord: string
  personSex: string
  personEmail: string
  personLandline: string
  personPhone: string
  personFacebook: string
  personIns: string
  personTiktok: string
  personYoutube: string
  personLinkedin: string
  personPostalCode: string
  companyName: string
  companyAbbrevia: string
  companyRange: string
  companyScale: string
  companyPostal: string
  companyPhone: string
  companyFax: string
  companyWebsite: string
  country: string
  timeZone: string
  city: string
  harbor: string
  addressPermanent: string
  addressMail: string
  sourceCode: string
  industryCode: string
  priorityCode: string
  starCode: string
  stageCode: string
  statusCode: string
  remark: string
  salesman : String
  creator: string  // 创建人
  createTime: string // 创建时间
  typeCode:string // 客户类型
}

// 客户信息 API
export const CustInfoApi = {
  // 分页查询
  getCustInfoPage: async (params: any) => {
    return await request.get({ url: `/business/cust-info/page`, params })
  },

  // 获取详情
  getCustInfo: async (id: number) => {
    return await request.get({ url: `/business/cust-info/get?id=` + id })
  },

  // 新增
  createCustInfo: async (data: CustInfoVO) => {
    return await request.post({ url: `/business/cust-info/create`, data })
  },

  // 修改
  updateCustInfo: async (data: CustInfoVO) => {
    return await request.put({ url: `/business/cust-info/update`, data })
  },

  // 删除
  deleteCustInfo: async (id: number) => {
    return await request.delete({ url: `/business/cust-info/delete?id=` + id })
  },

  // 导出
  exportCustInfo: async (params) => {
    return await request.download({ url: `/business/cust-info/export-excel`, params })
  },


  // 获取StageCode
  getStageCode: async () => {
    return await request.get({ url: `/business/cust-info/getStageCode`})
  },

  // 获取StatusCode
  getStatusCode: async () => {
    return await request.get({ url: `/business/cust-info/getStatusCode`})
  },

  // 获取StarCode
  getStarCode: async () => {
    return await request.get({ url: `/business/cust-info/getStarCode`})
  },

  // 获取PriorityCodee
  getPriorityCode: async () => {
    return await request.get({ url: `/business/cust-info/getPriorityCodee`})
  },

  // 获取IndustryCode
  getIndustryCode: async () => {
    return await request.get({ url: `/business/cust-info/getIndustryCode`})
  },

  // 获取SourceCode
  getSourceCode: async () => {
    return await request.get({ url: `/business/cust-info/getSourceCode`})
  },

  // 自行添加的一个接口,负责获取根据用户状态获取的客户状态
   updateCustStatus(id: number): Promise<void> {
    return request.post({ url: `/business/cust-info/update-status`, data: { id, status } })
  },

  // 修改业务员
updateSalesman(data: { ids: number[], salesmanId: number }) {
  return request.post({ url: '/business/cust-info/updateSalesman', data })
},


  // ✅ 获取客户状态下拉框列表

  getCustStatusList(): Promise<string[]> {
    return request.get({ url: `/business/cust-info/get-status-list` })
  },

 // ✅ 设置客户状态（传 id 和 status）params是get请求,是拼接在请求的URL当中的,data才是发送json数据
  setCustStatusById(id: number, status: string): Promise<number> {
    return request.post({
      url: `/business/cust-info/set-status-byId`,
      data: { id, status } // ✅ 正确写法
    })
  },
  getSalesmanTree: () => request.get({ url: '/business/cust-info/salesman/tree' })
};

// ✅ 独立导出 insertCustToHighSeas 函数
export function insertCustToHighSeas(data: {
  ids: number[]
  releaseReason: string
}) {
  return request.post({ url: '/business/cust-info/insert-cust-toHighSeas', data })
}
export function handoverSalesman(data: {
  ids: number[]
  targetSalesmanId: number
}) {
  return request.post({ url: '/business/cust-info/handoverSalesman', data })
}


// 客户联系人 VO
export interface CustContactsVO {
  id: number // id
  custId: number // 客户ID
  name: string // 姓名
  sex: string // 性别
  position: string // 职务
  email: string // 邮箱
  landline: string // 座机
  phone: string // 移动电话
  socialAcc: string // 社交账号
  facebook: string // Facebook
  ins: string // ins
  tiktok: string // tiktok
  youtube: string // Youtube
  linkedin: string // Linkedin
  remark: string // 备注
}

// 客户联系人 API
export const CustContactsApi = {
  // 查询客户联系人分页
  getCustContactsPage: async (params: any) => {
    return await request.get({ url: `/business/cust-contacts/page`, params })
  },

  // 查询客户联系人详情
  getCustContacts: async (id: number) => {
    return await request.get({ url: `/business/cust-contacts/get?id=` + id })
  },

  // 新增客户联系人
  createCustContacts: async (data: CustContactsVO) => {
    return await request.post({ url: `/business/cust-contacts/create`, data })
  },

  // 修改客户联系人
  updateCustContacts: async (data: CustContactsVO) => {
    return await request.put({ url: `/business/cust-contacts/update`, data })
  },

  // 删除客户联系人
  deleteCustContacts: async (id: number) => {
    return await request.delete({ url: `/business/cust-contacts/delete?id=` + id })
  },

  // 导出客户联系人 Excel
  exportCustContacts: async (params) => {
    return await request.download({ url: `/business/cust-contacts/export-excel`, params })
  },


}
